package webdav

import (
	"errors"
	"fmt"
	"golang.org/x/net/webdav"
	"log"
	"my189go/pkg"
	"net/http"
)

var errInvalidIfHeader = errors.New("webdav: invalid If header")

func Serve(addr string, client pkg.Drive, prefix string) {
	fs := &CloudFileSystem{
		Prefix: prefix,
		app:    client,
	}
	fs.handler = &webdav.Handler{
		Prefix:     prefix,
		FileSystem: fs,
		LockSystem: webdav.NewMemLS(),
		Logger: func(r *http.Request, err error) {
			log.Printf("req %s %s", r.Method, r.URL.Path)
			if err != nil {
				log.Printf("WebDAV error: %v", err)
			}
		},
	}

	err := http.ListenAndServe(addr, fs)
	//err := http.ListenAndServe(addr, nil)
	if err != nil {
		fmt.Println(err)
	}

}
